from lxml import etree
#这是一个lxmlDemo脚本
tree=etree.parse("html/b.html")
#xpath抓取抓取所有ul-li下内容
liResult=tree.xpath("/html/body/ul/li/a/text()")
#指定属性抓取 @href='jd'
liResult=tree.xpath("/html/body/ol/li/a[@href='jd']/text()")
#相对查找 .  拿取属性值@href
liResult=tree.xpath("/html/body/ol/li")
for i in liResult:
    #print(i.xpath("./a/text()"))
    print(i.xpath("./a/@href"))
